<?php
namespace app\admin\validate;


use think\Validate;
use app\admin\common\model\Admin;

class AddAdmin extends Validate
{
    protected $rule = [
        'username'  =>  'require|chsDash',
        'password'  =>  'require|length:4,25',
    ];

    protected $message = [
        'username.require'      =>  '用户名不能为空',
        'username.alphaDash'    =>  '用户名格式错误',
        'password.require'      =>  '密码不能为空',
        'password.length'       =>  '密码长度不符, 4-25个字符',
    ];

    public function checkUserName($userName)
    {
        $res = Admin::where('username',$userName)->find();
        if ($res) {
            exception('用户名已经存在啦');
        }
    }
}